Topic: Bypass Temp Directory

I need to know how to bypass the temp directory when downloading a file. I know its possible because other web based ftp's do it.

Re: Bypass Temp Directory

The standard PHP function ftp_get() downloads the files from the FTP server to the web server's /temp directory. There is no way around using a local file, unless you write your own ftp_get function; an example is posted on the PHP website - I didn't try it out:
http://www.php.net/manual/en/function.ftp-get.php#72603

Re: Bypass Temp Directory

the buffer in the socket pair is only about 364 bytes. So it doesn't work for files larger than that size.

Theres gotta be another way... How to big file websites do this? They dont move the file over to a temp directory first. This seems like it would be easy, but its not.
Is there a way to create just a link to the ftp with the user and pass? like ftp://username:password@ftpserver.com/directory/file

That seems like it would be easy, but I'm not very good at php and I wouldn't know what to change.

Re: Bypass Temp Directory

Hi.

I writed a method, using custom headers and readfile function for read ftp file content. On filesystem.inc.php:

function ftp_downloadfile($directory, $entry) {

    global $net2ftp_globals, $net2ftp_result, $net2ftp_settings;

    $conn_id = ftp_openconnection();
    if ($net2ftp_result["success"] == false)  { return false; }
    
    // Decrypt password
    if (isset($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]) == true) { 
        $net2ftp_password = decryptPassword($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]); 
    } else { 
        $net2ftp_password = decryptPassword($net2ftp_globals["password_encrypted"]); 
    }

        // Direct download
        
    header("Content-type: application/force-download");
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-disposition: attachment; filename=\"".$entry."\"");
    readfile("ftp://".$net2ftp_globals["username"].":".
                $net2ftp_password."@".
                $net2ftp_globals["ftpserver"].":".
                $net2ftp_globals["ftpserverport"].
                $directory.$entry);
    return false;

}

Maybe it'is not perfect, but it's faster and works for me big_smile

See ya

Last edited by daveruiz (2008-01-08 11:45:06)

Re: Bypass Temp Directory

daveruiz wrote:

Hi.

I writed a method, using custom headers and readfile function for read ftp file content. On filesystem.inc.php:

function ftp_downloadfile($directory, $entry) {

    global $net2ftp_globals, $net2ftp_result, $net2ftp_settings;

    $conn_id = ftp_openconnection();
    if ($net2ftp_result["success"] == false)  { return false; }
    
    // Decrypt password
    if (isset($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]) == true) { 
        $net2ftp_password = decryptPassword($_SESSION["net2ftp_password_encrypted_" . $net2ftp_globals["ftpserver"] . $net2ftp_globals["username"]]); 
    } else { 
        $net2ftp_password = decryptPassword($net2ftp_globals["password_encrypted"]); 
    }

        // Direct download
        
    header("Content-type: application/force-download");
    header("Content-Transfer-Encoding: Binary"); 
    header("Content-disposition: attachment; filename=\"".$entry."\"");
    readfile("ftp://".$net2ftp_globals["username"].":".
                $net2ftp_password."@".
                $net2ftp_globals["ftpserver"].":".
                $net2ftp_globals["ftpserverport"].
                $directory.$entry);
    return false;

}

Maybe it'is not perfect, but it's faster and works for me big_smile

See ya

Thank you so much for the MOD, I was looking for something like this for long time !
All the best!

Re: Bypass Temp Directory

By far one of the most important and greatest snips of code to add into the FTP client.   100% amazing smile well done.

For people that dont know how to use this piece of code, go to the file he told you to edit, search the function and take out and replace the whole function code.

Works a treat

Now can someone write an upload equivalent to this?

Last edited by BLACKHAWK (2010-07-19 22:56:21)

Re: Bypass Temp Directory

Hello everyone,

Thank you for this great snip of code, I do have one question though: when I add this code, all files are downloaded as 0kb in size. Is there any workaround for this?

Thanks in advance,

Jim Morris

Re: Bypass Temp Directory

Hi everybody,

This is exactly what I need, but I have the same problem as JimMorris has, the dowloaded files are only 1kb and cannot be opened after dowloading. Any ideas?

Thanks and cheers !

Re: Bypass Temp Directory

Thank you for the funciton, i've noticed that the files are downloading in the right way only in the root ftp directory.
Using subfolders I have the same problem of the other people.


The issue is that the function you worte works correctly if you change the parameters in ftp_downloadfile
because $directory miss a '/' at the end of his name.

Solution:
In modules\downloadfile there is downloadfile.inc.php that contains only the following function

function net2ftp_module_sendHttpHeaders() {

// --------------
// This function sends HTTP headers
// --------------

    global $net2ftp_globals, $net2ftp_settings;

    if ($net2ftp_settings["functionuse_downloadfile"] == "yes") {

//replace
        //ftp_downloadfile($net2ftp_globals["directory"], $net2ftp_globals["entry"]);
//with   
    ftp_downloadfile($net2ftp_globals["directory"]."/", $net2ftp_globals["entry"]);
//and that's all
    }
    else {
        $errormessage = __("This function has been disabled by the Administrator of this website.");
        setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
        return false;
    }
   
} // end net2ftp_sendHttpHeaders

Re: Bypass Temp Directory

Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! all the best!

Re: Bypass Temp Directory

I am happy to find so many useful information here in the post, we need develop more strategies in this regard, thanks for sharing.

Re: Bypass Temp Directory

These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post, writing is simply great, thank you for the post

Re: Bypass Temp Directory

Post is nicely written and it contains many good things for me. I am glad to find your impressive way of writing the post. Now it become easy for me to understand and implement the concept. Thanks for sharing the post.

Re: Bypass Temp Directory

Thanks for the nice blog. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us

Re: Bypass Temp Directory

It argues that a Greek naval blockade during the Trojan War kept Trojans on the European shore from intervening, and that they subsequently escaped to Italy where they were called Etruscans.

Re: Bypass Temp Directory

I am delighted to find many useful things here, that's superb. Thanks for sharing
marble polishing stone cleaning

Re: Bypass Temp Directory

Luckily, I am here again as I thought I’ve lost everything. Now, I am pretty much happy to enjoy your new posts and marvelous ideas on the topics. Here my family is joining reading me.
seattle moving companies

Re: Bypass Temp Directory

You have a very interesting blog, thanks for sharing.
cheap escorts London

Re: Bypass Temp Directory

The article is really interesting and informative, thank you. toronto  russian escort

Re: Bypass Temp Directory

What an interesting topic! Thanks for sharing it here toronto vip escort

Re: Bypass Temp Directory

The article is really interesting and informative, thank you. teen escort toronto

Re: Bypass Temp Directory

What an interesting topic! Thanks for sharing it here female escorts toronto

Re: Bypass Temp Directory

It's very good that I found this blog toronto escort service

Re: Bypass Temp Directory

Your info is appreciated,for I have been trying to know sth about it.Thank you.

Re: Bypass Temp Directory

Your info is appreciated,for I have been trying to know sth about it.Thank you. nike shox